<template>
  <div>
    <el-container>
      <el-main>
        <kendoForm
          :kendo-form-items="kendoFormItems"
          :kendo-form="kendoForm"
          :kendo-params-value="kendoParamsValue"
        />
      </el-main>
    </el-container>
    <el-container style="padding-left:5px">
      <el-main>
        <KendoGridCmpt
          :ref="'PrjMemberWeeklyKendoGrid'"
          :table-grid-option="tableGridOption"
          :table-grid-data-source-option="tableGridDataSourceOption"
          :table-grid-toolbar="tableGridToolbar"
          @persistSelection="selectDataItems"
        />
      </el-main>
    </el-container>
  </div>

</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'
  // import { isBlank } from '@/Utils/strUtil.js'
  export default {
    name: 'PrjmemberWeeklyPage',
    components: {
      kendoForm
    },
    data() {
      return {
        /* Form*/
        kendoFormItems: [
          {
            name: 'memberNo',
            label: '项目成员',
            paramName: 'memberNo',
            viewDisabled: true,
            controlType: 'multicolumncombobox',
            // change: this.devInChargeChange,
            dataSource: 'PrjMemberDataSource',
            dataType: 'json',
            autoBind: false,
            selectMultiple: true,
            transportReadUrl: '/service/prjMng/prjMemberMng/findPrjMemberList',
            dataMapping: {
              label: 'memberName',
              value: 'memberNo'
            },
            schema: {
              data: function(response) {
                if (typeof response.data === 'object') {
                  if (JSON.stringify(response.data) === '{}') {
                    return []
                  }
                }
                return response.data
              }
            },
            column: [
              {
                field: 'relPrjNo',
                title: '所属项目',
                width: 180
              },
              {
                field: 'memberNo',
                title: '项目成员编号',
                width: 120
              },
              {
                field: 'memberName',
                title: '项目成员编号',
                width: 120
              }
            ]
          },
          {
            name: 'weeklyWhichMonth',
            label: '周报年月',
            paramName: 'weeklyWhichMonth',
            controlType: 'datePicker',
            step: 'year',
            format: 'yyyy-MM'
          },
          {
            ref: 'WEEK_OF_MONTH_CD',
            remoteData: true,
            name: 'weekOfCurrentMonth',
            label: '周数',
            paramName: 'weekOfCurrentMonth',
            optionLabel: '--请选择--',
            controlType: 'dropDownList',
            filter: 'contains',
            dataType: 'json',
            transportReadUrl: '/service/sysMng/dict/findDictByTypeWithForm',
            autoBind: true,
            schema: {
              data: function(response) {
                return response.data
              }
            },
            dataMapping: {
              label: 'dictValNm',
              value: 'dictVal'
            },
            parameterMap: function(options, operation) {
              if (operation !== 'read' && options.models) {
                // eslint-disable-next-line no-undef
                return { models: kendo.stringify(options.models) }
              } else {
                // eslint-disable-next-line no-undef
                return kendo.stringify({ dict: 'WEEK_OF_MONTH_CD' })
              }
            }
          }
        ],
        kendoForm: {
          ref: 'prjForm',
          valid: 'valid',
          buttons: [
            {
              name: '查询', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'search',
              click: this.search
            },
            {
              name: '重置', // 按钮内容
              icon: 'reset-sm', // 按钮样式
              click: this.reset
            }
          ]
        },
        kendoParamsValue: {
          memberNo: '',
          weeklyWhichMonth: '',
          weekOfCurrentMonth: ''
        },

        /* Grid*/
        tableGridToolbar: [
          {
            text: '新增周报',
            class: 'k-primary',
            icon: 'add',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/projmng/prjmemberweekly/choicestaweek.vue',
              dialogTitle: '选择周报年月周数',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) edit(修改) del(删除) view(查看)
            */
            operatorType: 'add'
          },
          {
            text: '修改周报',
            class: 'k-primary',
            icon: 'edit',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/projmng/prjmemberweekly/weekly.vue',
              dialogTitle: '修改项目成员周报',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) edit(修改) del(删除) view(查看)
            */
            operatorType: 'edit'
          },
          {
            text: '周报统计',
            class: 'k-primary',
            icon: 'paste-plain-text',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/projmng/prjmemberweekly/choicestaweek.vue',
              dialogTitle: '选择周报年月周数',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) edit(修改) del(删除) view(查看)
            */
            operatorType: 'sta'
          }
        ],
        // maintain 需求信息数据列表
        tableGridOption: {
          ref: 'WeeklyDateGrid',
          dataSourceRef: 'weeklyDateSource',
          remoteData: true,
          sortable: true,
          reorderable: true,
          resizable: true,
          pageable: true,
          selectSingle: true,
          selectMultiple: false,
          columns: [
            {
              field: 'weeklyWhichMonth',
              title: '周报年月',
              width: 100
            },
            {
              field: 'weekOfCurrentMonth',
              title: '当前周数',
              width: 80,
              dictData: 'WEEK_OF_MONTH_CD'
            },
            {
              field: 'memberNo',
              title: '项目成员',
              width: 120,
              dictData: 'MEMBER_NO_CD'
            },
            {
              field: 'companyName',
              title: '公司名称',
              width: 180
            },
            {
              field: 'weeklyStartDate',
              title: '周报开始日期',
              width: 120
            },
            {
              field: 'weeklyEndDate',
              title: '周报结束日期',
              width: 120
            }
          ]
        },
        tableGridDataSourceOption: {
          ref: 'dictDataSource',
          type: 'json',
          pageSize: 10,
          transportReadUrl: '/service/prjMng/prjMemberMng/weekly/findPrjMemberWeeklyPage',
          serverPaging: true,
          remoteTransData: {
            MEMBER_NO_CD: {
              transportName: 'prjMemberMngServiceImpl',
              transportMethod: 'prjMemberTransDict',
              transportParam: {}
            }
          },
          dict: ['WEEK_OF_MONTH_CD'],
          params: {},
          schema: {
            model: {
              id: 'weeklyNo',
              fields: {
                weeklyNo: { editable: false, type: 'string' },
                memberNo: { editable: false, type: 'string' },
                companyName: { editable: false, type: 'string' },
                weeklyWhichMonth: { editable: false, type: 'string' },
                weekOfCurrentMonth: { editable: false, type: 'string' },
                weeklyStartDate: { editable: false, type: 'string' },
                weeklyEndDate: { editable: false, type: 'string' }
              }
            },
            data: function(response) {
              if (typeof response.data === 'object') {
                if (JSON.stringify(response.data) === '{}') {
                  return []
                }
              }
              return response.data.list
            },
            total: function(response) {
              if (typeof response.data === 'object') {
                if (JSON.stringify(response.data) === '{}') {
                  return 0
                }
              }
              return response.data.total
            }
          }
        },
        selectData: []
      }
    },
    mounted() {

    },
    methods: {
      /* grid*/
      parameterMap(options, operation) {
        if (operation !== 'read' && options.models) {
          // eslint-disable-next-line no-undef
          return { models: kendo.stringify(options.models) }
        } else {
          let parameterMap = {}
          parameterMap.pageNum = options.page
          parameterMap.pageSize = options.pageSize
          parameterMap = Object.assign(parameterMap, this.dataSourceOption.params)
          parameterMap = Object.assign(parameterMap, this.deepCopy(this.kendoParamsValue))
          return {
            // eslint-disable-next-line no-undef
            parameterMap: kendo.stringify(parameterMap)
          }
        }
      },
      selectDataItems(res) {
        this.selectData = res
      },
      search(paramVal, validator) {
        this.tableGridDataSourceOption.params = Object.assign(this.tableGridDataSourceOption.params, this.deepCopy(paramVal))
        this.tableGridDataSourceOption.params.pageNum = 1
        this.$refs['PrjMemberWeeklyKendoGrid'].transportReadGrid()
      },
      reset(paramVal) {
        Object.keys(paramVal).forEach(key => {
          if (Array.isArray(paramVal[key])) {
            this.kendoParamsValue[key] = []
          } else {
            this.kendoParamsValue[key] = ''
          }
        })
        this.$refs['PrjMemberWeeklyKendoGrid'].transportReadGrid()
      }
    }
  }
</script>

<style>

</style>
